package com.xiaoxx.utils;


import com.xiaoxx.common.result.R;
import com.xiaoxx.enums.AliyunRType;

/**
 * @author :HX
 * @date : 2023/7/11
 */
public class FileUploadUtil {

    public static R<String> getPath(String filePath, String fileName) {
        if (filePath.lastIndexOf("/") != filePath.length() - 1) {
            return R.error(AliyunRType.FILE_UPLOAD_FAILED.getValue(), "The path must end with [/]");
        }
        // 文件名中对url中不安全的字符处理
        fileName = fileName.replaceAll("\\+", "")
                .replaceAll(" ", "")
                .replaceAll("/", "")
                .replaceAll("\\?", "")
                .replaceAll("%", "")
                .replaceAll("#", "")
                .replaceAll("&", "")
                .replaceAll("=", "");
        return R.success(fileName);
    }
}
